import React from 'react'
import store from '../../store/store'
import {incrementAction,decrementAction,waitDecrementAction} from '../../store/actions/countAction'
export default function Count() {  
    const {count} =store.getState().count
    const incrementHandle = ()=>{
        //改变这个值
        store.dispatch(incrementAction(1))
    }

    const decrementHandle = ()=>{
        store.dispatch(decrementAction(1))
    }

    const ifOddDecrementHandle = ()=>{
        if(count%2!==0){
            store.dispatch(incrementAction(1))
        }
    }

    const waitDecrementHandle = ()=>{
        store.dispatch(waitDecrementAction(1))
    }


  return (
    <div>
        <h1>我是Count组件 我的值是{count}</h1>
        <h4>当前的电影总数是多少{}</h4>
        <button onClick={incrementHandle}>累加</button>
        <button onClick={decrementHandle}>累减</button>
        <button onClick={ifOddDecrementHandle}>当是奇数的时候加1</button>
        <button onClick={waitDecrementHandle}>2秒之后加1</button>
    </div>
  )
}
